###
#R Script to display survey demographics and issue summary
###

library(xtable)
library(plyr)

####
#Survey Demographics
###

load('survey1.demos.RData')
load('survey2.demos.RData')

demo.frame1 <- survey1.demos[,c('black','hispanic.binary','white','other.race','college','female','age','income','democrat','republican','independent')]

demo.frame2 <- survey2.demos[,c('black','hispanic.binary','white','other.race','college','female','age','income','democrat','republican','independent')]

demo.frame1 <- apply(X=demo.frame1,MARGIN=2,FUN=mean,na.rm=TRUE)
demo.frame1 <- as.data.frame(t(t(demo.frame1)))
demo.frame1 <- round(demo.frame1,digits=2)

demo.frame2 <- apply(X=demo.frame2,MARGIN=2,FUN=mean,na.rm=TRUE)
demo.frame2 <- as.data.frame(t(t(demo.frame2)))
demo.frame2 <- round(demo.frame2,digits=2)

combined.frame <- cbind.data.frame(demo.frame1,demo.frame2)

#Table A1 - Appendix
xtable(combined.frame)

####
#Survey 2 Evaluations of Issues
###

load('experiment.issue.evaluation.RData')

issue.output <- ddply(experiment.issue.evaluation,.(issue),summarise,important=round(mean(importance,na.rm=TRUE),digits=2),certainty=round(mean(certainty,na.rm=TRUE),digits=2),sen1=round(mean(ifelse(sen1.perceived==0, 1, 0),na.rm=TRUE),digits=2),sen2=round(mean(ifelse(sen2.perceived==0, 1, 0),na.rm=TRUE),digits=2))
issue.output$sen.knowledge <- round(x=((issue.output$sen1+issue.output$sen2)/2),digits=2)
issue.output$sen1 <- NULL
issue.output$sen2 <- NULL

#Table A2 - Appendix
xtable(issue.output[order(issue.output$important,decreasing=TRUE),])
